'use strict';

exports.main = async (event, context) => {

	// 获取 `user` 集合的引用
	/*
	{"result":[{"id":"1","typeId":"0","name":"推荐"},{"id":"2","typeId":"10","name":"张万森下雪了"},{"id":"3","typeId":"2","name":"圣诞专属"},{"id":"4","typeId":"1","name":"性感舞蹈"},{"id":"5","typeId":"3","name":"婚纱写真"},{"id":"6","typeId":"4","name":"仙侠古装"},{"id":"7","typeId":"5","name":"帅气男生"},{"id":"8","typeId":"6","name":"甜美风"},{"id":"9","typeId":"7","name":"纯欲风"},{"id":"10","typeId":"8","name":"高级写真"},{"id":"11","typeId":"9","name":"手势舞"},{"id":"13","typeId":"11","name":"慢动作"}]}
	*/
   
	const collection = db.collection('videoType');
	for (var i = 0; i < event.length; i++) {
		let item = event[i];
		console.log('item : ', item)
		let count = await collection.where({"typeId":item.typeId}).count();
		console.log('collection.where : ', count)
		if(count.total === 0){
			let res = await collection.add(item);
			console.log('add : ', res)
		}
	}
	//返回数据给客户端
	return event
};
